#----------让我们开始函数吧-------------

# def hello():
#     print ('Howdy!')
#     print('Howdy!!!')
#     print('Hello there.')

# hello()
# hello()
# hello()
#定义、调用、传递、参数、变元
# def hello(name):
#     print('Hello,'+name)

# hello('Alice')
# hello('Bob')

# import random

# def getAnswer(answerNumber):
#     if answerNumber == 1:
#         return 'It is certain'
#     elif answerNumber == 2:
#         return 'of course'
#     elif answerNumber == 3:
#         return 'Yes'
#     elif answerNumber == 4:
#         return 'GG hendar'

# r = random.randint(1,4)
# fortune = getAnswer(r)
# print(fortune)

# print(getAnswer(random.randint(1,4)))

#---------None(?)------------------
# spam = print('Hello')
# None == spam

#-----关键字参数和print()函数
# print('Hello')
# print('World')

# print('Hello',end='')
# print('world')

# print('dog','cat','pig')
# print('dog','cat','pig',sep=',')

#-------调用栈-------------
def a():
    print('a() starts')
    b()
    d()
    print('a() returns')

def b():
    print('b() starts')
    c()
    print('b() returns')

def c():
    print('c() starts')
    print('c() returns')

def d():
    print('d() starts')
    print('d() returns')

print(a())


#局部和全局作用域
#1.局部变量不能在全局作用域内使用
# def spam():
#     eggs = 31337
# spam()
# print(eggs)
#2.局部作用域不能使用其他局部作用域内的变量
# def spam():
#     eggs = 99
#     bacon()
#     print(eggs)

# def bacon():
#     ham = 101
#     eggs = 0

spam()
#3.全局变量可以在局部作用域中读取
def egg():
    print(eggs)
eggs = 100
spam()
print(eggs)
#4.避免在不同作用域内使用相同变量名
